package com.five.monkey.feign.es.convert;

import com.five.monkey.feign.es.dao.model.Graph;
import com.five.monkey.util.TimeUtils;
import com.five.monkey.vo.GraphVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @author 狻猊
 * @date 2022-03-28 20:28:57
 */
public class GraphConvert {

    private GraphConvert() {}

    public static GraphVo esModel2vo(Graph graph) {
        if (Objects.isNull(graph)) {
            return null;
        }
        GraphVo vo = new GraphVo();
        BeanUtils.copyProperties(graph, vo);
        return vo;
    }

    public static Graph vo2esModel(GraphVo vo) {
        if (Objects.isNull(vo)) {
            return null;
        }
        Graph graph = new Graph();
        BeanUtils.copyProperties(vo, graph);
        if (StringUtils.isBlank(graph.getCreateTime())) {
            graph.setCreateTime(TimeUtils.parseDate());
        }
        if (StringUtils.isBlank(graph.getUpdateTime())) {
            graph.setUpdateTime(TimeUtils.parseDate());
        }
        return graph;
    }
}
